package na.learn.java.corepatterns.pooling;

public class HostSpecificParams {

	private String url;

	private String username;

	private String password;

	private String driverClassName;

	private boolean autoCommit;

	private int transactionIsolation;

	private int staleAfterTimeMillisecs;

	public HostSpecificParams() {
		super();
	}

	public HostSpecificParams(String url, String username, String password,
			String driverClassName) {
		super();
		this.url = url;
		this.username = username;
		this.password = password;
		this.driverClassName = driverClassName;
	}

	public HostSpecificParams update(HostSpecificParams newHostParams) {
		this.autoCommit = newHostParams.isAutoCommit();
		this.driverClassName = newHostParams.getDriverClassName();
		this.password = newHostParams.getPassword();
		this.staleAfterTimeMillisecs = newHostParams
				.getStaleAfterTimeMillisecs();
		this.transactionIsolation = newHostParams.getTransactionIsolation();
		this.username = newHostParams.getUsername();
		return this;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof HostSpecificParams) {
			HostSpecificParams newHostParams = (HostSpecificParams) obj;
			if (this.autoCommit == newHostParams.isAutoCommit()
					&& this.driverClassName.equals(newHostParams.getDriverClassName())
					&& this.username.equals(newHostParams.getUsername())
					&& this.password.equals(newHostParams.getPassword())
					&& this.staleAfterTimeMillisecs == newHostParams.getStaleAfterTimeMillisecs())
				
				return true;
			else
				return false;

		} else
			return false;
	}

	public boolean isAutoCommit() {
		return autoCommit;
	}

	public void setAutoCommit(boolean autoCommit) {
		this.autoCommit = autoCommit;
	}

	public int getStaleAfterTimeMillisecs() {
		return staleAfterTimeMillisecs;
	}

	public void setStaleAfterTimeMillisecs(int staleAfterTimeMillisecs) {
		this.staleAfterTimeMillisecs = staleAfterTimeMillisecs;
	}

	public int getTransactionIsolation() {
		return transactionIsolation;
	}

	public void setTransactionIsolation(int transactionIsolation) {
		this.transactionIsolation = transactionIsolation;
	}

	public String getDriverClassName() {
		return driverClassName;
	}

	public void setDriverClassName(String driverClassName) {
		this.driverClassName = driverClassName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
}
